using System;
using System.Collections.Generic;
using System.Text;
using Edge.Common.DataUtils;
using Edge.Common.Utils;
using Edge.Common.Utils;

namespace Edge.Common.ComponentModel
{
    [AttributeUsage(AttributeTargets.Class)]
    public class RelatedTypeAttribute : Attribute
    {
        Type type;


        public RelatedTypeAttribute(Type type)
        {
            if (type == null)
                throw new ArgumentException("type");
            this.type = type;
        }


        public Type Type
        {
            get { return type; }
        }

        public static Type GetRelatedTypeOrSelf(Type type)
        {
            RelatedTypeAttribute relatedAttr = ReflectionUtils.GetFirstAttribure<RelatedTypeAttribute>(type, true);

            if (relatedAttr != null)
            {
                type = relatedAttr.Type;
            }

            return type;
        }
    }
}
